/**
 * File Name   : FinancialService.java
 * Description : 
 */
package com.hh.admin.model.financial.service;

import java.sql.SQLException;

import org.apache.log4j.Logger;

import com.hh.admin.model.financial.form.FinancialForm;
import com.hh.admin.model.financial.form.ParamFinancialBean;
import com.hh.admin.model.financial.form.ResultFinancialBean;
import com.hh.common.ibatis.dao.IQueryDao;
import com.hh.common.ibatis.dao.IUpdateDao;

/**
 * 理财课堂Service
 * @author 冯昌硕
 * @create 2013-1-22 下午8:41:07
 */
public class FinancialService {

    private static final Logger log = Logger.getLogger(FinancialService.class);

    private IQueryDao queryDao;
    
    private IUpdateDao updateDao;
    
    /**
     * 新增理财课堂内容记录
     * @param form 表单Form
     * @return
     * @throws SQLException
     * @create 2013-1-22 下午9:51:03
     */
    public int insertFinancial(FinancialForm form) throws SQLException {
        ParamFinancialBean paramBean = new ParamFinancialBean();
        paramBean.setTitle(form.getTitle());
        paramBean.setDetailContent(form.getDetailContent());
        paramBean.setCreateUser(form.getCreateUser());
        paramBean.setStatus(form.getStatus());
        
        log.debug("新增理财课堂信息 paramBean=[" + paramBean + "]");
        return (Integer) updateDao.insert("financial.insertFinancial", paramBean);
    }
    
    /**
     * 删除理财课堂内容记录
     * @param id 要删除的记录ID
     * @return
     * @throws SQLException
     * @create 2013-1-22 下午9:55:16
     */
    public int deleteOneFinancial(int id) throws SQLException {
        return updateDao.delete("financial.deleteFinancial", id);
    }
    
    /**
     * 批量删除理财课堂记录
     * @param ids 要删除的理财课堂ID
     * @return
     * @throws SQLException
     * @create 2013-1-22 下午9:57:29
     */
    public int deleteManyFinancial(Integer[] ids) throws SQLException {
        return updateDao.batchDelete("financial.deleteFinancial", ids);
    }
    
    /**
     * 获取理财课堂记录详情
     * @param id 理财课堂ID
     * @return 理财课堂详情
     * @throws ClassCastException
     * @throws SQLException
     * @create 2013-1-20 下午9:01:27
     */
    public ResultFinancialBean getFinancialDetail(int id) throws ClassCastException, SQLException {
        return queryDao.queryForObject("financial.selFinancialDetail", id, ResultFinancialBean.class);
    }
    
    /**
     * 更新理财课堂信息
     * @param form 表单项
     * @return
     * @throws SQLException
     * @create 2013-1-20 下午10:32:42
     */
    public int updateFinancial(FinancialForm form) throws SQLException {
        ParamFinancialBean paramBean = new ParamFinancialBean();
        paramBean.setTitle(form.getTitle());
        paramBean.setDetailContent(form.getDetailContent());
        paramBean.setStatus(form.getStatus());
        paramBean.setId(form.getId());
        
        log.debug("更新理财课堂信息 paramBean=[" + paramBean + "]");
        return updateDao.update("financial.undateFinancial", paramBean);
    }

    public void setQueryDao(IQueryDao queryDao) {
        this.queryDao = queryDao;
    }

    public void setUpdateDao(IUpdateDao updateDao) {
        this.updateDao = updateDao;
    }
    
}
